<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>自定义查询</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div class="ccpui-tablesize" style="padding:10px;">
    <table id="formQuery" lay-filter="formQuery"></table>
</div>
</body>
<script type="text/html" id="formQueryToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                <span>添加</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="delete">
                <i class="layui-icon layui-icon-delete"></i>
                <span>刪除</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
        </div>
        <form class="layui-form" action="" style="margin-top:10px" lay-filter="formQuery_query">
            <div class="table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">名称 </label>
                    <input type="text" name="Q_name_SL" id="name" class="layui-input filter-value" placeholder="名称"
                           autocomplete="off"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">别名 </label>
                    <input type="text" name="Q_alias_SL" id="alias" class="layui-input filter-value" placeholder="别名"
                           autocomplete="off"/>
                </div>
            </div>
        </form>
    </div>
</script>

<script type="text/html" id="manageBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="preview">预览</a>
</script>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'table', 'layer', 'jquery', 'form', 'tree', 'commons', 'common', 'totalFilter', 'setter'], function () {
        var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,
            common = layui.common, totalFilter = layui.totalFilter, $ = layui.jquery;
        var tableH = commons.tabHeight();
        common.tableSort("formQuery");
        //渲染表格
        table.render({
            elem: '#formQuery'
            , cellMinWidth: 80
            , title: '自定义查询表'
            , defaultToolbar: []
            , height: tableH
            , url: serverPath.formPath + setter.formLinkPath + 'formQuery/list'
            , toolbar: '#formQueryToolsBar'
            , page: true
            , autoSort: false
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'name', title: '名称', sort: true, align: 'center'}
                , {field: 'alias', title: '别名', sort: true, align: 'center'}
                , {field: 'objName', title: '对象名称', align: 'center'}
                , {field: 'dsname', title: '数据源名称', align: 'center'}
                , {fixed: 'right', title: '管理', toolbar: '#manageBar', width: 200, align: 'center'}
            ]]
            , done: function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel')
            }
        });
        totalFilter.init('formQuery');
        table.on('toolbar(formQuery)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'delete':
                    if (data.length === 0) {
                        layer.alert('请选择记录!');
                    } else {
                        layer.confirm('确认删除吗？', {
                            btn: ['是', '否'] //按钮
                        }, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            var queryIds = ids.join(',');
                            var t_date = {"ids": queryIds};
                            $.ajax({
                                url: serverPath.formPath + setter.formLinkPath + "formQuery/del",
                                data: t_date,
                                dataType: 'json',
                                success: function (data) {
                                    layer.alert(data.msg);
                                    //执行重载
                                    table.reload('formQuery', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                    totalFilter.init('formQuery');
                                }
                            });
                        });
                    }
                    break;
                case 'query':
                    common.tableConditionRender("formQuery", "formQuery_query", {where: {}}, false);
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        title: "添加查询",
                        shade: 0.3,
                        area: ['750px', '500px'],
                        content: serverPath.formPath + setter.formLinkPath + "formQuery/view/add"
                    });
                    break;
                case 'reset':
                    common.tableConditionRender("formQuery", "formQuery_query", {where: {}}, true);
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(formQuery)', function (obj) {
            switch (obj.event) {
                case 'del':
                    layer.confirm('确认删除吗？', function (index) {
                        var selId = obj.data.id;
                        var t_date = {"ids": selId};
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath + "formQuery/del",
                            data: t_date,
                            dataType: 'json',
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                table.reload('formQuery', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                totalFilter.init('formQuery');
                            }
                        });
                    });
                    break;
                case 'edit':
                    var formQueryId = obj.data.id;
                    var alias = obj.data.alias;
                    layer.open({
                        type: 2,
                        title: "编辑",
                        shade: 0.3,
                        area: ['750px', '500px'],
                        content: serverPath.formPath + setter.formLinkPath + "formQuery/view/add?formQueryId=" + formQueryId + "&alias=" + alias
                    });
                    break;
                case 'preview':
                    var alias = obj.data.alias;
                    layer.open({
                        type: 2,
                        title: "预览",
                        shade: 0.3,
                        area: ['700px', '500px'],
                        content: serverPath.formPath + setter.formLinkPath + "formQuery/view/preview?alias=" + alias
                    });
                    break;
            }
        });
    });
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>